#pragma once

#include <sys/epoll.h>
#include "Log.hpp"
class Epoller
{
public:
    Epoller()
    {
        _epfd = epoll_create(1);
        LOG(DEBUG, "epollfd create success, fd is %d", _epfd);
    }
    void AddEvent(int fd, uint32_t event)
    {
        struct epoll_event ev;
        ev.events = event;
        ev.data.fd = fd;
        epoll_ctl(_epfd, EPOLL_CTL_ADD, fd, &ev);
    }
    void DelEvent(int sockfd)
    {
        epoll_ctl(_epfd, EPOLL_CTL_DEL, sockfd, nullptr);
    }
    void ModEvent(int sockfd, uint32_t events)
    {
        struct epoll_event ev;
        ev.data.fd = sockfd;
        ev.events = events;
        epoll_ctl(_epfd, EPOLL_CTL_MOD, sockfd, &ev);
    }
    int WaitEvent(struct epoll_event *events, int gnum, int timeout)
    {
        int n = epoll_wait(_epfd, events, gnum, timeout);
        return n;
    }
    ~Epoller()
    {
    }

private:
    int _epfd;
};